package com.hw.protocol.tool.decode.hw;

import com.hw.protocol.tool.model.entity.hw.AbsFlowMeter;
import com.hw.protocol.tool.model.entity.hw.Dtu61;

/**
 * @author : lihy
 * @date : 2023/3/23 10:06
 * description: 流量计(6130/6131)实时数据解码器
 */
public class Dtu61Decode extends FlowMeterDecodeTemplate {

    private Dtu61 fm;

    public Dtu61Decode(AbsFlowMeter fm, byte[] data) {
        super(fm, data);
        this.fm = (Dtu61) fm;
    }

    @Override
    protected boolean dtu61() {
        return true;
    }

    @Override
    protected void setVolume() {
        if (fm.isDefaultVolume()) {
            fm.setVolume(dataBuf.readUnsignedIntLE());
        } else {
            fm.setVolume(dataBuf.readDoubleLE());
        }
    }

    @Override
    protected void setRealVolume() {
        if (fm.isDefaultVolume()) {
            fm.setRealVolume(dataBuf.readUnsignedIntLE());
        }
    }

    @Override
    protected void setExternalTemp() {
        fm.setExternalTemperature(dataBuf.readFloatLE());
    }

    @Override
    protected void setExternalPress() {
        fm.setExternalPress1(dataBuf.readFloatLE());
        fm.setExternalPress2(dataBuf.readFloatLE());
    }
}
